package nature.nano.util.pipe;

import nature.nano.component.EmptyProps;
import nature.nano.component.PrimaryPipe;
import nature.nano.component.Strings;
import nature.nano.iface.Props;

public class EventMixer extends PrimaryPipe {

	private int rootCount = 0;
	
	@Override
	public void anBegin(String type, Props props) {
		if (type.contains(Strings.root)) {
			if (rootCount == 0) {
				slot(Strings.output).onBegin(Strings.root, EmptyProps.instance);
			}
			rootCount++;
		} else {
			slot(Strings.output).onBegin(type, props);			
		}
	}

	@Override
	public void anEnd(String type) {
		if (type.contains(Strings.root)) {
			rootCount--;
			if (rootCount == 0){
				slot(Strings.output).onEnd(Strings.root);			
			}
		} else {
			slot(Strings.output).onEnd(type);
		}
	}
	
}
